//
//  UserInfo.m
//  HuLaQuan
//
//  Created by hok on 1/18/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "UserInfo.h"

@interface UserInfo ()

@property (nonatomic, readwrite) NSMutableDictionary *userInformations; // of user info
@property (nonatomic, strong) NSString *ID;
@end

@implementation UserInfo
- (void)setUserInformations:(NSMutableDictionary *)userInformations
{
    _userInformations = userInformations;
    [self saveUserDetailedInfo];
    
}

- (instancetype)initWithID:(NSString *)userid andToken:(NSString *)token
{
    self = [super init];
    if (self) {
        self.ID = userid;
        
        [self loadUserInfo];
    }
    return self;
}

- (void)loadUserInfo
{
    NSDictionary *info = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"UserInfo"];
    
    
    self.userInformations = [info mutableCopy];
    
}


- (void)saveUserDetailedInfo
{
    [YuUserDefaultsUtilities saveValue:[self.userInformations copy] forKey:@"UserInfo"];
    
    // [[NSUserDefaults standardUserDefaults] setObject:(NSDictionary *)self.userInformations forKey:@"UserInfo"];
}

- (void)clearUserDetailedInfo
{
    self.userInformations = nil;
    [self saveUserDetailedInfo];
}
- (void)modifyUserInformation:(NSString *)key withValue:(NSString *)value
{
    self.userInformations[key] = value;
}
@end
